﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Security.Permissions;
using System.Web.Mvc;
using Orchard.Environment.Extensions;

namespace Downplay.Mechanics.Impulses
{
    [OrchardFeature("Downplay.Mechanics.Impulses")]
    public class Impulse : IImpulse
    {
        public Impulse(string name, string prefix, string displayName, IEnumerable<Permission> permissions = null)
        {
            Name = name;
            Prefix = prefix;
            DisplayName = displayName;
            Permissions = permissions ?? Enumerable.Empty<Permission>();
        }

        public string Name { get; protected set; }
        public string Prefix
        {
            get;
            protected set;
        }

        public string DisplayName { get; set; }

        public IEnumerable<Permission> Permissions { get; set; }

        public virtual String Url(HtmlHelper html, System.Web.Mvc.UrlHelper url, Orchard.ContentManagement.IContent content)
        {
            return url.Action("Actuate", "Impulse", new
            {
                area = "Downplay.Mechanics",
                returnUrl = html.ViewContext.HttpContext.Request.RawUrl,
                sourceId = content.Id,
                name = Name,
                prefix = Prefix
            });
        }
    }
}